<template>
  <div class="file-system-container">
    <div class="header">
      <h1 class="system-title">文件系统</h1>
      <nav class="top-nav">
        <div class="nav-item">
          <el-dropdown trigger="click">
            <el-button 
              type="text" 
              style="color: inherit; padding: 0.5rem 1rem;"
              class="nav-btn">
              个人中心
            </el-button>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="$router.push('/login')">退出登录</el-dropdown-item>
                <el-dropdown-item @click="navigateToVersion">密钥管理</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
        <div class="nav-item">
          <el-dropdown trigger="click">
            <el-button 
              type="text" 
              style="color: inherit; padding: 0.5rem 1rem;"
              class="nav-btn">
              公证中心
            </el-button>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="$router.push('/Face')">申请私钥</el-dropdown-item>
                <el-dropdown-item @click="$router.push('/Nota')">文件公证</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </nav> 
    </div>
    
    <div class="file-system-content"> 
      <div class="file-tree-wrapper">
        <FileTree :node="fileTree" />
      </div>
    </div>
    


    <!-- 悬浮按钮 -->
    <div v-show="showTransferButton" class="transfer-button-wrapper">
      <el-button 
        class="transfer-button" 
        type="primary" 
        circle 
        @click="openTransferManager" 
        
      >
        <svg class="transfer-icon" viewBox="0 0 24 24">
          <path d="M19,9H15V3H9V9H5L12,16L19,9M5,18V20H19V18H5Z" />
        </svg>
      </el-button>
    </div>
    
    <!-- 文件传输管理窗口 -->
    <ManagerWindow 
      v-show="showTransferManager"
      ref="managerWindow" 
      @close="closeTransferManager"
    />
  
  </div>
</template>

<script setup>
import router from '@/router';
import FileTree from '../components/FileTree.vue';
import { ElButton, ElIcon } from 'element-plus'
import ManagerWindow from '../components/ManagerWindow.vue'; // 确保路径正确
import { ref, onMounted, onBeforeUnmount,reactive } from 'vue';
const showTransferButton = ref(true);
const showTransferManager = ref(false);
const managerWindow = ref(null);

const openTransferManager = () => {
  showTransferManager.value = true;
  showTransferButton.value = false;
};

const closeTransferManager = () => {
  showTransferManager.value = false;
  showTransferButton.value = true;
};



const props = defineProps({
  fileTree: {
    type: Object,
    default: null
  },
  loading: {
    type: Boolean,
    default: false
  },
  error: {
    type: String,
    default: null
  }
});

// 导航到版本页面
const navigateToVersion = () => {
  router.push('/version');
};
</script>

<style scoped>


/* 悬浮按钮样式 */
.transfer-button-wrapper {
  position: fixed;
  right: 30px;
  bottom: 30px;
  z-index: 100;
  transition: transform 0.3s ease;
}

.transfer-button-wrapper:hover {
  transform: scale(1.05);
}

.transfer-button {
  width: 60px;
  height: 60px;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  background: linear-gradient(135deg, #409eff, #337ecc);
  border: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

.transfer-button:hover {
  transform: translateY(-3px) rotate(5deg);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  background: linear-gradient(135deg, #66b1ff, #409eff);
}

.transfer-icon {
  width: 28px;
  height: 28px;
  fill: white;
}

/* 管理器窗口样式 */
.manager-window {
  position: fixed;
  z-index: 9999;
  bottom: 20px;
  right: 20px;
  contain: strict; /* 性能优化 */
  will-change: transform; /* 提示浏览器优化 */
  transition: transform 0.1s ease-out; /* 更快的过渡 */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  overflow: hidden;
  background: white;
}



.file-system-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(to bottom, #f0f5ff, #e6f7ff);
  position: relative;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}



.system-title {
  text-align: center;
  color: #2c3e50;
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.top-nav {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 20px;
  align-items: center;
}

.file-system-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  width: 100%;
}

.file-tree-wrapper {
  width: 66.66%;
  max-width: 1200px;
  min-width: 800px;
  height: 80vh;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 20px;
}

/* 独立的浮动按钮容器 */
.floating-button-wrapper {
  position: fixed;
  right: 30px;
  bottom: 30px;
  z-index: 100;
}

.floating-button {
  width: 60px;
  height: 60px;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.3s, box-shadow 0.3s;
}

.floating-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* 管理器窗口样式 */
.manager-window {
  position: fixed;
  z-index: 9999;  /* 提升层级 */
  transform: translate(var(--x), var(--y));
  contain: layout;
  top: 0;
  left: 0;
}

.window-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.window-container .header {
  padding: 16px 20px;
  border-bottom: 1px solid #ebeef5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 0;
}

.window-container .header .el-icon {
  cursor: pointer;
  font-size: 18px;
  transition: color 0.3s;
}

.window-container .header .el-icon:hover {
  color: #F56C6C;
}

.manager-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
  background: #fafbfc;
}

.nav-btn {
  transition: all 0.3s;
}

.nav-btn:hover {
  color: var(--el-color-primary) !important;
  background-color: rgba(64, 158, 255, 0.05) !important;
}

@media (max-width: 1200px) {
  .file-tree-wrapper {
    width: 85%;
    min-width: 95%;
    height: 85vh;
  }
}

@media (max-width: 768px) {
  .file-tree-wrapper {
    width: 100%;
    min-width: 100%;
    height: 80vh;
    padding: 10px;
    border-radius: 8px;
  }

  .system-title {
    font-size: 1.8rem;
    margin-bottom: 15px;
  }

  .top-nav {
    position: static;
    margin-top: 10px;
  }

  .nav-item {
    padding: 8px 16px;
  }
  
  .floating-button-wrapper {
    right: 20px;
    bottom: 20px;
  }
  
  .floating-button {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
}
</style>